#!/bin/bash
SCRIPT_BASE_DIR=$( dirname "${BASH_SOURCE[0]}" )
source "${SCRIPT_BASE_DIR}/common/fs_utils.sh"

cmd=$( basename "$0" )
if [ $# -ne 1 ]
then
	echo "Usage: ${cmd} <root_dir>"
	exit 1
fi

root="$1"
# dir_exists_or_die "$1/src/caffe"

csFile="${root}/cscope.files"
echo "Build ${csFile} ..."
find "${root}/fs" -name "*.c" > "${csFile}"
find "${root}/ipc" -name "*.c" >> "${csFile}"
find "${root}/kernel" -name "*.c" >> "${csFile}"
find "${root}/net" -name "*.c" >> "${csFile}"
find "${root}/block" -name "*.c" >> "${csFile}"
find "${root}/lib" -name "*.c" >> "${csFile}"
find "${root}/drivers" -name "*.c" >> "${csFile}"
find "${root}/init" -name "*.c" >> "${csFile}"
find "${root}/mm" -name "*.c" >> "${csFile}"
find "${root}/arch/ia64" -name "*.c" >> "${csFile}"
find "${root}/arch/x86" -name "*.c" >> "${csFile}"
# ignore arch other than ia64
# ignore tools, security, usr, certs, crypto, samples, virt
find "${root}/fs" -name "*.h" >> "${csFile}"
find "${root}/ipc" -name "*.h" >> "${csFile}"
find "${root}/kernel" -name "*.h" >> "${csFile}"
find "${root}/net" -name "*.h" >> "${csFile}"
find "${root}/block" -name "*.h" >> "${csFile}"
find "${root}/lib" -name "*.h" >> "${csFile}"
find "${root}/drivers" -name "*.h" >> "${csFile}"
find "${root}/init" -name "*.h" >> "${csFile}"
find "${root}/mm" -name "*.h" >> "${csFile}"
find "${root}/arch/ia64" -name "*.h" >> "${csFile}"
find "${root}/arch/x86" -name "*.c" >> "${csFile}"

echo "Build cscope DB..."
oldDir=$( pwd )
cd ${root}
cscope -Rbqk
cd ${oldDir}

echo "Done."

